<?php
	$TH_Month = array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
	$TH_Month_short = array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
	$start = 1;
?>
	<div class="header">
		&nbsp;&nbsp;กิจกรรมเดือน <?php echo $TH_Month[$dataModuleCalendarElement['m']];?> <?php echo $dataModuleCalendarElement['y'];?>
		<a title="ถัดไป" href="javascript:void(0);" class="next">&gt;</a>
		<a title="ก่อนหน้า" href="javascript:void(0);" class="prev">&lt;</a> 
	</div>
	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
		<thead>
			<tr>
				<th>SUN</th>
				<th>MON</th>
				<th>TUE</th>
				<th>WED</th>
				<th>THU</th>
				<th>FRI</th>
				<th>SAT</th>
			</tr>
		</thead>	
		<tbody>
			<?php for($i=0;$i<6;$i++):?>
			<?php if($start > $dataModuleCalendarElement['month_end']) continue;?>
			<tr>
				<?php for($j=0;$j<7;$j++):?>
					<?php if($i==0):?>
						<?php if($dataModuleCalendarElement['month_start'] <= $j):?>
							<td valign="top">
								<?php if(!empty($dataModuleCalendarActivity[$start][0])):?>
								<a href="javascript:void(0);" class="balloon">
									<div class="image">
										<?php echo exec_image(array(
											'folder' => 'calendar',
											'dimension' => '90x90',
											'file_name' => @$dataModuleCalendarActivity[$start][0]['image']->calendar_file_name.'.'.@$dataModuleCalendarActivity[$start][0]['image']->calendar_file_ext,
											'alt' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].'',	
											'title' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].''	
										)
									);?>								
									</div>
								</a>
								<div style="display:none;">
									<ul>
										<?php foreach($dataModuleCalendarActivity[$start] as $value):?>
										<li><a href="<?php echo base_url().'calendar/archives/'.$value['calendar_id'].'-'.seo_url($value['calendar_subject']);?>" target="_blank"><?php echo $value['calendar_subject'];?></a></li>
										<?php endforeach;?>
									</ul>
								</div>	
								<?php endif;?>
								<span <?php echo ($dataModuleCalendarElement['d']==$start ? 'class="current"':'');?>><?php echo $start;?></span>
							</td>
							<?php $start++;?>
						<?php else:?>
							<td>&nbsp;</td>
						<?php endif;?>
					<?php else:?>
						<?php if($start <= $dataModuleCalendarElement['month_end']):?>
							<td valign="top">
								<?php if(!empty($dataModuleCalendarActivity[$start][0])):?>
								<a href="javascript:void(0);" class="balloon">
									<div class="image">
										<?php echo exec_image(array(
											'folder' => 'calendar',
											'dimension' => '90x90',
											'file_name' => @$dataModuleCalendarActivity[$start][0]['image']->calendar_file_name.'.'.@$dataModuleCalendarActivity[$start][0]['image']->calendar_file_ext,
											'alt' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].'',	
											'title' => ''.@$dataModuleCalendarActivity[$start][0]['calendar_subject'].''	
										)
									);?>								
									</div>
								</a>
								<div style="display:none;">
									<ul>
										<?php foreach($dataModuleCalendarActivity[$start] as $value):?>
										<li><a href="<?php echo base_url().'calendar/archives/'.$value['calendar_id'].'-'.seo_url($value['calendar_subject']);?>" target="_blank"><?php echo $value['calendar_subject'];?></a></li>
										<?php endforeach;?>
									</ul>
								</div>								
								<?php endif;?>						
								<span <?php echo ($dataModuleCalendarElement['d']==$start ? 'class="current"':'');?>><?php echo $start;?></span>
							</td>
							<?php $start++;?>
						<?php else:?>
							<td>&nbsp;</td>
						<?php endif;?>
					<?php endif;?>
				<?php endfor;?>
			</tr>
			<?php endfor;?>
		</tbody>
	</table>
	<br />
	<div id="news">
		<!--ข่าว-->
		<div class="header"><span>ปฏิทินกิจกรรม</span></div>
		<ul class="news_block_style4">
			<?php if(!empty($dataModuleCalendarActivity)):?>
				<?php foreach($dataModuleCalendarActivity as $key => $value):?>
					<?php foreach($value as $items):?>
						<li>
							<a href="<?php echo base_url();?>calendar/archives/<?php echo $items['calendar_id'].'-'.seo_url($items['calendar_subject']);?>" target="_blank">
								<div class="image">
									<?php echo exec_image(array(
										'folder' => 'calendar',
										'dimension' => '165x200',
										'file_name' => @$items['image']->calendar_file_name.'.'.@$items['image']->calendar_file_ext,
										'alt' => ''.$items['calendar_subject'].'',	
										'title' => ''.$items['calendar_subject'].''	
										)
									);?>
								</div>
							</a>
							<div class="info">
								<div class="label">
									<div class="date"><?php echo $key;?></div>
									<div class="month"><?php echo $TH_Month_short[$dataModuleCalendarElement['m']];?></div>
								</div>					
								<a href="<?php echo base_url();?>calendar/archives/<?php echo $items['calendar_id'].'-'.seo_url($items['calendar_subject']);?>" target="_blank">
									<h3><?php echo $items['calendar_subject'];?></h3>
									<div><strong>เริ่มกิจกรรม:</strong> <?php echo $items['calendar_datetime'];?></div>
									<div><strong>สถานที่:</strong> <?php echo $items['calendar_place'];?></div>
								</a>
								<p><?php echo $items['calendar_brief'];?></p>
							</div>
						</li>
					<?php endforeach;?>
				<?php endforeach;?>
			<?php else:?>
			<li class="empty">ไม่มีข้อมูลกิจกรรมเดือนนี้</li>
			<?php endif;?>				
		</ul>
	</div>
<script type="text/javascript" language="javascript">
(function($) {
/*whatever jQuery stuff*/
	$(function(){
		$('#news_calendar').find('.next').click(function(){
			$.ajax({
				type:'post',
				url:web_path+'calendar',
				data:({
					ajax:true,
					month:'<?php echo (($dataModuleCalendarElement["m"]+1) > 12 ? 1:($dataModuleCalendarElement["m"]+1));?>',
					year:'<?php echo (($dataModuleCalendarElement["m"]+1) > 12 ? ($dataModuleCalendarElement["y"]+1):$dataModuleCalendarElement["y"]);?>',
				})
			}).done(function(data){
				$('#news_calendar').html(data);
			});
		});
		$('#news_calendar').find('.prev').click(function(){
			$.ajax({
				type:'post',
				url:web_path+'calendar',
				data:({
					ajax:true,
					month:'<?php echo (($dataModuleCalendarElement["m"]-1) < 1 ? 12:($dataModuleCalendarElement["m"]-1));?>',
					year:'<?php echo (($dataModuleCalendarElement["m"]-1) < 1 ? ($dataModuleCalendarElement["y"]-1):$dataModuleCalendarElement["y"]);?>',
				})
			}).done(function(data){
				$('#news_calendar').html(data);
			});
		});	
		//Balloon
		$(".balloon").each(function() { $(this).balloon({ contents: $(this).next().html(), position: "top" }); });
		if($(".jquery_balloon").length > 0){
			$(".jquery_balloon").remove();
		}
	});	
})(jQuery);
</script>	